package com.zzh.takeoutapp.activity;

import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.TextView;

import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.base.BaseActivity;
import com.zzh.takeoutapp.entity.OrderListBean;
import com.zzh.takeoutapp.utils.CountTimerUtlis;
import com.zzh.takeoutapp.utils.ToolBarHelper;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/8/9.
 */

public class PayOrderActivity extends BaseActivity {

    @Bind(R.id.tv_pay_time)
    TextView tv_pay_time;
    @Bind(R.id.tv_shop_name)
    TextView tv_shop_name;
    @Bind(R.id.tv_money)
    TextView tv_money;
    @Bind(R.id.tv_submit)
    TextView tv_submit;
    @Bind(R.id.toolbar)
    Toolbar tbToolbar;
    private CountTimerUtlis countTimerUtlis;
    private OrderListBean orderListBean;

    @Override
    public void setContent() {
        setContentView(R.layout.activity_pay_order);
        ButterKnife.bind(this);
    }

    @Override
    public void initComponent() {
        ToolBarHelper.setTitleAndBackAndText(this, tbToolbar, "支付订单");
        String dateline = getIntent().getStringExtra("dateline");
        if (dateline != null) {
            countTimerUtlis = new CountTimerUtlis(Long.parseLong(dateline) * 1000,
                    1000, tv_pay_time, R.string.order_time, new CountTimerUtlis.Call() {
                @Override
                public void END() {
                    tv_pay_time.setTextColor(getResources().getColor(R.color.color_red));
                    countTimerUtlis.cancel();
                }
            });
            countTimerUtlis.start();
        }
    }

    @Override
    public void setListener() {
        if (getIntent().getSerializableExtra("orderListBean") != null) {
            orderListBean = (OrderListBean) getIntent().getSerializableExtra("orderListBean");
            tv_shop_name.setText(orderListBean.getShop_title()
                    + "  " + orderListBean.getPhone());
            tv_money.setText("￥" + orderListBean.getMoney());
            countTimerUtlis = new CountTimerUtlis(Long.parseLong(orderListBean.getPay_ltime()) * 1000,
                    1000, tv_pay_time, R.string.order_time, new CountTimerUtlis.Call() {
                @Override
                public void END() {
                    tv_pay_time.setTextColor(getResources().getColor(R.color.color_red));
                    countTimerUtlis.cancel();
                }
            });
            countTimerUtlis.start();
        } else {
            tv_shop_name.setText(getIntent().getStringExtra("shop_title")
                    + "  " + getIntent().getStringExtra("shop_mobile"));
            tv_money.setText("￥" + getIntent().getStringExtra("money"));
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onAfterInit() {

    }


}
